<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<html>
<head>
    <title>Title</title>
    <style>
        .box {
            padding: 5px;
            width: 90%;
            margin: auto;
        }
    </style>
    <script src="${pageContext.request.contextPath}/statics/js/jquery-1.8.3.min.js"></script>
    <script>
        function doPage(pageNo) {
            document.forms[0].pageNo.value = pageNo;
            document.forms[0].submit();
        }

        function doUpdate(id) {
            document.forms[0].method = 'get';
            document.forms[0].action = '${pageContext.request.contextPath}/stu/update/' + id;
            document.forms[0].submit();
        }

        function doUpload(id) {
            document.forms[0].method = 'get';
            document.forms[0].action = '${pageContext.request.contextPath}/stu/upload/' + id;
            document.forms[0].submit();
        }

        function doDel(id) {
            if (confirm('确定删除吗？')) {
                $.getJSON('${pageContext.request.contextPath}/stu/del', {id: id}, function (result) {
                    alert(result ? '删除成功' : '删除失败');
                    document.forms[0].submit();
                })
            }
        }
        $(function () {
            $.getJSON('${pageContext.request.contextPath}/stuClass/list',function (result) {
                for(let item of result) {
                    if ('${queryParams.studentClassId}' == item.id) {
                        $("[name=studentClassId]").append("<option selected value='"+item.id+"'>"+item.cname+"</option>")
                    } else {
                        $("[name=studentClassId]").append("<option value='"+item.id+"'>"+item.cname+"</option>")
                    }
                }
            })
        })
    </script>
</head>
<body>
<div class="box">
<form action="${pageContext.request.contextPath}/stu/list">
    <input name="pageNo" type="hidden" value="${page.pageNum}">
    <div>
        学号<input name="studentNo" value="${queryParams.studentNo}">
        姓名<input name="studentName" value="${queryParams.studentName}">
        班级<select name="studentClassId"><option value="">请选择</option></select>
        <input type="submit" value="查询"/>
    </div>
    <input type="button" value="添加" onclick="location.href='${pageContext.request.contextPath}/stu/add'">
    <div>
        <table>
            <tr style="background-color: gray;">
                <td>学号</td>
                <td>姓名</td>
                <td>性别</td>
                <td>头像</td>
                <td>正面</td>
                <td>反面</td>
                <td>入学日期</td>
                <td>手机号</td>
                <td>所在班级</td>
                <td>技能</td>
                <td>操作</td>
            </tr>
            <c:forEach items="${page.list}" var="item">
                <tr>
                    <td>${item.stuno}</td>
                    <td>${item.realname}</td>
                    <td>${item.sex == 0 ? "男" : "女"}</td>
                    <td>
                        <img width="32" height="32" style="border-radius: 50%;" src="http://localhost:8080/files/${item.faceimg}">
                    </td>
                    <td>
                        <c:if test="${item.idcardPositive == null}">未上传</c:if>
                        <c:if test="${item.idcardPositive != null}"><img width="32" height="32" src="http://localhost:8080/files/${item.idcardPositive}"></c:if>
                    </td>
                    <td>
                        <c:if test="${item.idcardNegative == null}">未上传</c:if>
                        <c:if test="${item.idcardNegative != null}"><img width="32" height="32" src="http://localhost:8080/files/${item.idcardNegative}"></c:if>
                    </td>
                    <td><fmt:formatDate pattern="yyyy-MM-dd" value="${item.admissionDate}"/></td>
                    <td>${item.phone}</td>
                    <td>${item.className}</td>
                    <td>${item.skillNames}</td>
                    <td>
                        <a href="javascript:doDel(${item.id})">删除</a>
                        <a href="${pageContext.request.contextPath}/stu/update/${item.id}">修改</a>
                        <a href="${pageContext.request.contextPath}/stu/upload/${item.id}">上传身份证</a>
                    </td>
                </tr>
            </c:forEach>
        </table>
        <a href="javascript:doPage(1)">首页</a>
        <c:if test="${page.pageNum>1}"><a href="javascript:doPage(${page.pageNum-1})"><<</a></c:if>
        <c:forEach begin="1" end="${page.pages}" var="item">
            <a <c:if test="${item == page.pageNum}">style="color: red;"</c:if> href="javascript:doPage(${item})">${item}</a>
        </c:forEach>
        <c:if test="${page.pageNum<page.pages}"><a href="javascript:doPage(${page.pageNum+1})">>></a></c:if>
        <a href="javascript:doPage(${page.pages})">尾页</a>
    </div>
    <div style="text-align: center;">
        共${page.total}条，当前是第${page.pageNum}页，每页${page.pageSize}条，共${page.pages}页
    </div>
</form>
</div>
</body>
</html>
